package com.share.thread;

import java.util.*;

/**
 * 
 * @author Johnny Tam
 * 中断你线程执行 Demo
 */
public class TestInterrupt {
	public static void main(String[] args) {
		MyThread thread = new MyThread();
		thread.start();
		try {
			Thread.sleep(10000);
			System.out.println("我已经休眠了10s钟！！！");
			System.out.println("线程名字： " + Thread.currentThread().getName() 
	        		 + "  " + Thread.currentThread().getId()
	        		 + "  " + Thread.currentThread().getPriority());
		} catch (InterruptedException e) {
		}
		thread.interrupt();// 中断线程执行。
	}
}

class MyThread extends Thread {
	boolean flag = true;

	public void run() {
		while (flag) {
			System.out.println("===" + new Date() + "===" + Thread.currentThread().getId());
			try {
				sleep(1000);
			} catch (InterruptedException e) {
				return;//退出while
			}
		}
	}
}